﻿using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PlanningGIS.Win.Controls
{
    /// <summary>
    /// 选择打开文件夹
    /// </summary>
    public partial class OpenFolder : UserControl
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public OpenFolder()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 获取或设置是否可以编辑路径
        /// </summary>
        public bool ReadOnly
        {
            get { return txtPath.ReadOnly; }
            set { txtPath.ReadOnly = value; }
        }

        /// <summary>
        /// 获取或设置当前选择的路径
        /// </summary>
        public string SelectedPath
        {
            get { return txtPath.Text.Trim(); }
            set { txtPath.Text = value; }
        }

        /// <summary>
        /// 选择路径
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOpen_Click(object sender, EventArgs e)
        {
            if (txtPath.Text.Trim() != "")
            {
                if (Directory.Exists(txtPath.Text))
                {
                    folderBrowserDialog1.SelectedPath = txtPath.Text.Trim();
                }
            }
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                txtPath.Text = folderBrowserDialog1.SelectedPath;
            }
        }
    }
}
